
package guiprototype;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JToolBar;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JButton;

import guiprototype.Strings;
import guiprototype.World;
import guiprototype.MapPanel;
import guiprototype.InfoPanel;


public class AppFrame extends JFrame implements ActionListener {

    World world;

    JToolBar toolbar;
    //JStatusBar statusbar;

    MapPanel mappanel;
    InfoPanel infopanel;
        
    JScrollPane mapscroller;
    JScrollPane infoscroller;
     
    JSplitPane splitpane;

    public AppFrame(World w) {
        super(Strings.frameTitle);

        // This GUI is constructed for a specific game world
        world = w;
        
        // TODO: Ask to save first.
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        
        // Setup general GUI stuff
        setLayout(new BorderLayout());
        defineMenus();
        defineToolbar();
        defineStatusbar();
        
        // The main two GUI components
        mappanel = new MapPanel(world);
        infopanel = new InfoPanel(world);
        
        // Wrap panels in scrollers
        mapscroller = new JScrollPane(mappanel);
        infoscroller = new JScrollPane(infopanel);
        mapscroller.setMinimumSize(new Dimension(0,0));
        infoscroller.setMinimumSize(new Dimension(0,0));
        
        // Wrap scrollers in a split pane
        splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mapscroller, infoscroller);
        splitpane.setDividerLocation(0.5);
        splitpane.setOneTouchExpandable(true);
        add(splitpane, BorderLayout.CENTER);
        
        pack();
        setVisible(true);
    }

    void defineMenus() {
        JMenuBar jmb = new JMenuBar();

        JMenu file = new JMenu("File");
        JMenuItem item;
        file.add(item = new JMenuItem("New"));
        item.addActionListener(this);
        file.add(item = new JMenuItem("Open"));
        item.addActionListener(this);
        file.addSeparator();
        file.add(item = new JMenuItem("Exit"));
        item.addActionListener(this);
        jmb.add(file);
 
        setJMenuBar(jmb);
    }

    void defineToolbar() {
        // TODO: Add something useful here, add listeners

        toolbar = new JToolBar();

        JButton myButton = new JButton("Toolbar button");
        toolbar.add(myButton);

        //Icon tigerIcon = new ImageIcon("SmallTiger.gif");
        //myButton = new JButton(tigerIcon);
        //toolbar.add(myButton);

        //toolbar.addSeparator();

        //toolbar.add(new Checkbox("Not"));

        add(toolbar, BorderLayout.NORTH);
    }

    void defineStatusbar() {
        // TODO: Use this for information
        //statusbar = new JStatusBar();
        //add(statusbar, BorderLayout.SOUTH);
    }

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}

